package org.hcyspartnoc.demo.controller.traProgram;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.hcyspartnoc.demo.common.core.AjaxResult;
import org.hcyspartnoc.demo.common.core.annotation.Log;
import org.hcyspartnoc.demo.common.core.annotation.PreAuthorize;
import org.hcyspartnoc.demo.common.core.enums.BusinessType;
import org.hcyspartnoc.demo.common.exception.traProgram.MajorException;
import org.hcyspartnoc.demo.entity.Major;
import org.hcyspartnoc.demo.entity.Scheme;
import org.hcyspartnoc.demo.pojo.dto.traProgram.TraProgramNodeDto;
import org.hcyspartnoc.demo.pojo.dto.traProgram.UpdateNodeDto;
import org.hcyspartnoc.demo.pojo.vo.traProgram.MajorVo;
import org.hcyspartnoc.demo.pojo.vo.traProgram.NoumenonVO;
import org.hcyspartnoc.demo.pojo.vo.traProgram.TraProgramVO;
import org.hcyspartnoc.demo.pojo.vo.traProgram.VersionVo;
import org.hcyspartnoc.demo.service.traProgram.ITraProgramService;
import org.hcyspartnoc.demo.service.traProgram.impl.MajorServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/traProgram")
public class TraProgramController {
    @Resource
    private ITraProgramService traProgramService;

    @Log(title = "培养方案·本体·获取·全部", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "tp:noumenon:get:all", descr = "获取本体列表")
    @GetMapping("/noumenon/get/list")
    public AjaxResult getNoumenon()  {
        List<NoumenonVO> noumenonVOS = traProgramService.getNoumenon();
        return AjaxResult.success(noumenonVOS);
    }


    @Log(title = "培养方案·专业版本·获取·专业", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "tp:version:get:all", descr = "获取用户权限下的培养方案版本列表")
    @GetMapping("/version/get/list")
    public AjaxResult getVersions()  {
        List<VersionVo> versionVos = traProgramService.getVersions();
        return AjaxResult.success(versionVos);
    }


    @Log(title = "培养方案·图谱·获取·专业版本", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "tp:chart:get:all", descr = "获取培养方案图谱")
    @GetMapping("/chart/get/list")
    public AjaxResult getChart(@NotNull @RequestParam Integer majorVersionId)  {
        Scheme scheme = traProgramService.getChart(majorVersionId);
        return AjaxResult.success(scheme);
    }

    @Log(title = "培养方案·图谱·获取·全部", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "tp:chart:get:all", descr = "获取培养方案图谱")
    @GetMapping("/chart/get/all")
    public AjaxResult getChartALL()  {
        List<Major> major = traProgramService.getChartAll();
        return AjaxResult.success(major);
    }

    @Log(title = "培养方案·图谱·添加·节点", businessType = BusinessType.INSERT)
    @PreAuthorize(auth = "tp:chart:get:node", descr = "添加各种类型的培养方案节点")
    @PostMapping("/chart/insert/node")
    public AjaxResult createTraProNode(@Valid @RequestBody TraProgramNodeDto traProgramNodeDto)  {
        traProgramService.createTraProNode(traProgramNodeDto);
        return AjaxResult.success();
    }

    @Log(title = "培养方案·图谱·删除·节点", businessType = BusinessType.INSERT,isSaveResponseData = false)
    @PreAuthorize(auth = "tp:chart:delete:node", descr = "删除各种类型的培养方案节点")
    @DeleteMapping ("/chart/delete/node")
    public AjaxResult deleteTraProNode(@NotNull @RequestParam Integer nodeId)  {
        traProgramService.deleteTraProNode(nodeId);
        return AjaxResult.success();
    }

    @Log(title = "培养方案·图谱·更新·节点", businessType = BusinessType.INSERT,isSaveResponseData = false)
    @PreAuthorize(auth = "tp:chart:update:node", descr = "更新培养方案节点")
    @PutMapping  ("/chart/update/node")
    public AjaxResult updateTraProNode(@Valid @RequestBody UpdateNodeDto updateNodeDto)  {
        traProgramService.updateTraProNode(updateNodeDto);
        return AjaxResult.success();
    }
}
